@extends("admin.common.admin")

<title>添加管理员 - 管理员管理 - H-ui.admin v3.1</title>
@section("cnt")
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i>
        首页
        <span class="c-gray en">&gt;</span>
        用户修改
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>
    <article class="page-container">
        @include("admin.common.msg")
        <form class="form form-horizontal" id="form-admin-add" method="post" action="{{ route("admin.admin.update",["id" => $data["id"]]) }}">
            @csrf
            @method("PUT")
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" readonly value="{{ $data["username"] }}" placeholder="" id="username" name="username">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>真实姓名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{ $data["truename"] }}" placeholder="" id="truename" name="truename">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否修改密码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="checkbox" name="" id="checkbut">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>性别：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input name="sex" value="先生" type="radio" @if($data["sex"]=="先生") checked @endif>
                        <label for="sex-1">先生</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="sex-2" value="女士" name="sex" @if($data["sex"]=="女士") checked @endif>
                        <label for="sex-2">女士</label>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{ $data["phone"] }}" placeholder="" id="phone" name="phone">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" placeholder="@"  value="{{ $data["email"] }}" name="email" id="email">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">角色：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width:150px;">
                        <select class="select" name="role_id" size="1">
                            <option  value="{{ $data["role_id"] }}" name="role_id">{{ $data["role"]["name"] }}</option>
                            @foreach($list as $item)
                                    <option  value="{{ $item["id"] }}" name="role_id">{{ $item["name"] }}</option>
                            @endforeach
                        </select>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>
@endsection
@section("js")
    <script type="text/javascript">
        var html = `
            <div class="row pass cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>初始密码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="password" name="password">
                </div>
            </div>
            <div class="row pass cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="password" class="input-text" autocomplete="off"  placeholder="确认新密码" id="password_confirmed" name="password_confirmation">
                </div>
            </div>`;
        $("#checkbut").click(function () {

            console.log($(this).prop("checked"));
            if($(this).prop("checked")){
               $(this).parents(".row").after(html);
            }else{
                $(".pass").remove();
            }
        })


        $(function(){
            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });

            $("#form-admin-add").validate({
                rules:{
                    username:{
                        required:true,
                        minlength:2
                    },
                    truename:{
                        required:true,
                        minlength:2
                    },
                    password:{
                        required:true,
                    },
                    password_confirmed:{
                        required:true,
                        equalTo: "#password"
                    },
                    sex:{
                        required:true,
                    },
                    phone:{
                        required:true,
                        isPhone:true,
                    },
                    email:{
                        required:true,
                        email:true,
                    },
                    // adminRole:{
                    //     required:true,
                    // },
                },
                onkeyup:false,
                success:"valid",
                submitHandler:function(form){
                    form.submit();
                    // $(form).ajaxSubmit({
                    //     type: 'post',
                    //     url: "xxxxxxx" ,
                    //     success: function(data){
                    //         layer.msg('添加成功!',{icon:1,time:1000});
                    //     },
                    //     error: function(XmlHttpRequest, textStatus, errorThrown){
                    //         layer.msg('error!',{icon:1,time:1000});
                    //     }
                    // });
                    // var index = parent.layer.getFrameIndex(window.name);
                    // parent.$('.btn-refresh').click();
                    // parent.layer.close(index);
                }
            });
            jQuery.validator.addMethod("phone",function (value,element) {
                var tel = "/^1[3-9]\d{9}$/";
                return this.optional(element) || (tel.test(value));
            },"请输入正确的手机号")
        });
    </script>
@endsection
